﻿Imports Phila
Imports Phila.Sql
Imports Phila.CommonClasses
Imports System.IO

Public Class EditGallery
    Inherits System.Web.UI.Page
    Public Shared intId As Integer
    Public Shared strData As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If Not IsPostBack = True Then
                ajaxFileUpload.Enabled = False
                Dim strSql As String

                If LCase(Request.QueryString("type")) = "t" Then
                    Fill_ComboBox(cmbTours, "Select Id, (Name + ' - ' + TourCode) as Name from ptn_Tours where IsActive=1 order by Name")
                Else
                    Fill_ComboBox(cmbTours, "Select Id, Name from ptn_Hotels where IsActive=1 order by Name")
                End If
                hdType.Value = Request.QueryString("type")
                additem(cmbTours, "--Select--", 0)

                If Not LCase(Request.QueryString("gid")) Is Nothing Then
                    plGallery.Visible = True
                    strSql = "select * from ptn_Gallery order by Id desc"
                    Fill_dtList(dlGallery, strSql)
                Else

                End If
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub ajaxFileUpload_UploadComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AjaxFileUploadEventArgs) Handles ajaxFileUpload.UploadComplete
        Try
            If Not Session("TourID") Is Nothing Then
                Dim fileName As String
                Dim Type As String
                If Not LCase(Request.QueryString("type")) Is Nothing Then
                    Type = "t"
                Else
                    Type = "h"
                End If
                'getThumbnail(ajaxFileUpload, e.FileName, Type, txtSummary.Text.Replace("'", "&#039"))
                getThumbnail(ajaxFileUpload, e.FileName, Type, Session("TourID"))
                fileName = Replace(e.FileName, "..", ".")
                fileName = "g-" & Session("TourID") & "-" & fileName
                Dim txt As Array
                txt = RetriveData("select top 1 Id from ptn_Gallery where Image='" & fileName & "'", 0)
                'strData = "Insert into ptn_TourGallery(GalleryId, TourId) Values(" & txt(0) & "," & cmbTours.SelectedValue & ")"
                Response.Write(txt(0))
                If LCase(Request.QueryString("type")) = "t" Then
                    Insert_Update_Delete_Record("Insert into ptn_TourGallery(GalleryId, TourId) Values(" & txt(0) & ",'" & Session("TourID").ToString & "')")
                    Response.Write("Insert into ptn_TourGallery(GalleryId, TourId) Values(" & txt(0) & ",'" & Session("TourID").ToString & "')")
                Else
                    Insert_Update_Delete_Record("Insert into ptn_HotelGallery(GalleryId, HotelId) Values(" & txt(0) & ",'" & Session("TourID").ToString & "')")
                End If
                'Response.Redirect("ViewGallery.aspx")
            Else
                Exit Sub
                lblMsg.Text = "Please select Tour"
                lblMsg.Enabled = True
                lblMsg.ForeColor = Drawing.Color.Red
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub btnRemove_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim itm As DataListItem = dlGallery.Items(0)
        Dim strId As String = itm.FindControl("Id").ToString
    End Sub

    Private Sub cmbTours_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbTours.SelectedIndexChanged
        'If cmbTours.SelectedValue = 0 Then
        '    ajaxFileUpload.Enabled = False
        'Else
        '    ajaxFileUpload.Enabled = True
        'End If
        Session("TourID") = cmbTours.SelectedValue

        'plGallery.Visible = True
        'Fill_dtList(dlGallery, "select g.* from ptn_Gallery g inner join ptn_TourGallery tg on tg.GalleryId=g.id where tg.tourid=" & cmbTours.SelectedValue)

    End Sub

End Class